#include "StdAfx.h"
#include "String.h"

using namespace Torrent::Bencode;

String::String(std::istream& stream)
{
    int size;
    stream >> size;

    if (stream.fail() || stream.get() != ':')
    {
        return; //throw...
    }

    _value.resize(size);

    std::string::iterator it;
    for (it = _value.begin(); it != _value.end() && stream.good(); ++it)
    {
        *it = (char)stream.get();
    }


    if (stream.fail())
    {
        return; //throw...
    }

}

String::~String(void)
{
}

void String::print( std::ostream& stream, bool debug /*= false*/ )
{
    //NOTE << _value not working ??
    stream << _value.size() << ":" << _value.c_str();
}